package com.danger.Model.action;

import android.content.Context;

import com.danger.Model.listener.OnUploadPhotoListener;
import com.danger.Util.CheckCode;

import java.io.File;

import cn.bmob.v3.datatype.BmobFile;
import cn.bmob.v3.listener.UploadFileListener;

/**
 * Created by danger on 2016/4/4.
 */
public class UploadPhotoModelImpl implements UploadPhotoModel {

    private Context context;

    public UploadPhotoModelImpl(Context context) {
        this.context = context;
    }

    @Override
    public void upload(String path, final OnUploadPhotoListener listener) {
        final BmobFile bmobFile = new BmobFile(new File(path));
        bmobFile.uploadblock(context, new UploadFileListener() {
            @Override
            public void onSuccess() {
                listener.onSuccess(bmobFile.getFileUrl(context));
            }

            @Override
            public void onFailure(int i, String s) {
                listener.onError(CheckCode.checkByCode(i));
            }
        });
    }
}
